/**
 * 转账管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="margin-t10">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>转账管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="boxBlock"> 
      <div class="serachTop"> 
           <!-- 搜索筛选 -->
            <el-form :inline="true" :model="formInline" class="user-search">
              <el-form-item  >
                <el-input
                  size="small"
                  v-model="formInline.userId"
                  placeholder="输入用户id"
                  type="number"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="">
                <el-input
                  size="small"
                  v-model="formInline.orderNo"
                  placeholder="输入订单编号"
                  type="number"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="">
                <el-select
                  size="small"
                  v-model="formInline.status"
                  placeholder="请选择审核状态"
                  clearable
                >
                  <el-option label="请选择审核状态" value=""></el-option>
                  <el-option
                    v-for="type in statusData"
                    :label="type.key"
                    :value="type.value"
                    :key="type.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button
                  size="small"
                  type="primary"
                  icon="el-icon-search"
                  @click="search"
                  >搜索</el-button
                >
              </el-form-item>
            </el-form>
            <el-button size="small" type="primary" @click="exportEx()">
              导出
            </el-button>
      </div> 
    <!--列表-->
    <div class="ra_box"> 
      <el-table
        size="small"
        :data="listData"
        highlight-current-row
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 100%"
        v-if="listData"
      >
        <el-table-column prop="userId" label="用户ID" fixed="left"  width="100" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="updateBy"
          label="操作人"
          show-overflow-tooltip
          width="120"
        >
        </el-table-column>
        <el-table-column prop="orderNo" label="订单编号" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="amount" label="转账金额" show-overflow-tooltip>
          <template slot-scope="scope">
            <div>{{ b(scope.row.amount) }}</div>
          </template>
        </el-table-column>
        <!-- <el-table-column   prop="editUser" label="收款码" >
      </el-table-column> -->
        <el-table-column
          prop="createTime"
          label="转账时间"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ timestampToTime(scope.row.createTime) }}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="审核状态" show-overflow-tooltip>
          <template slot-scope="scope">
            <div>{{ statusData[scope.row.status].key }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="150">
          // <template slot-scope="scope">
          //   <el-button
          //     size="mini"
          //     :type="scope.row.status == '0' ? 'text' : ''"
          //     @click="handleEdit(scope.$index, scope.row)"
          //   >
          //     {{ scope.row.status == 0 ? "审核" : "查看" }}
          //   </el-button>
          // </template>

          <template slot-scope="scope">
            <el-button
              size="mini"  
              type="success" plain  
              @click="handleEdit(scope.$index, scope.row)"
              v-if="scope.row.status == '0'" 
            >
            审核 
            </el-button>
            <el-button
              size="mini"   plain 
              v-else  
              @click="handleEdit(scope.$index, scope.row)"
            >
               查看 
            </el-button>
            
          </template>

        </el-table-column>
      </el-table>
    </div>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
  </div>
    <!-- 审核界面 -->
    <el-dialog
      title="查看详情"
      :close-on-click-modal="false"
      :visible.sync="editFormVisible"
      width="30%"
      @close="closeDialog"
      v-if="editForm"
    >
      <el-form :model="editForm" :rules="rules" ref="editForm">
        <el-form-item label="转账ID" prop="userId">
          {{ editForm.userId }}
        </el-form-item>
        <el-form-item label="转账金额" prop="amount">
          {{ b(editForm.amount) }}
        </el-form-item>
        <el-form-item label="收款人ID" prop="toUserId">
          {{ editForm.toUserId }}
        </el-form-item>
        <el-form-item label="收款人" prop="toUserName">
          {{ editForm.toUserName }}
        </el-form-item>
        <el-form-item label="转账时间" prop="createTime">
          {{ timestampToTime(editForm.createTime) }}
        </el-form-item>
        <el-form-item label="转账备注" prop="remark">
          {{ editForm.remark }}
        </el-form-item>
        <el-form-item label="审核备注" prop="auditResult">
          <el-input
            size="small"
            v-model.trim="editForm.auditResult"
            auto-complete="off"
            type="textarea"
            :rows="5"
            placeholder="请输入备注"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          :disabled="disabled"
          @click="submitForm(1)"
          v-if="editForm.status == 0"
        >
          通过
        </el-button>
        <el-button
          type="danger"
          :disabled="disabled"
          @click="submitForm(2)"
          v-if="editForm.status == 0"
        >
          驳回
        </el-button>
      </div>
    </el-dialog>
    <codeChoose ref="codeRef" :fromType="verType" @setParam="getParam" ></codeChoose>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import codeChoose from '@/components/codeChoose.vue'
import {
  setStoreS,
  getStoreS,
  removeStoreS,
  insertCharacter,
  timestampToTime,
  spStr,
} from "../../utils/util";
import {
  baseURL,
  req,
  service,
  encrypt,
  decrypt,
  reqtoken,
  reqField,
  format,
  getUrl,
  reqJson 
} from "../../api/axiosFun";
import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
      loading: false,
      editFormVisible: false,
      disabled: false,
      b: format,
      timestampToTime: timestampToTime,
      statusData: [
        { key: "待审核", value: 0 },
        { key: "通过", value: 1 },
        { key: "驳回", value: 2 },
      ],
      editForm: "",
      // rules表单验证
      rules: {
        transferAmount: [
          { required: true, message: "请输入转账金额", trigger: "blur" },
          {
            pattern: /^\d+(\.\d{1,2})?$/,
            message: "请输入正整数或者2位数小数",
            trigger: "blur",
          },
        ],
        receivingCode: [
          { required: true, message: "请输入收款码", trigger: "blur" },
        ],
      },
      formInline: {
        userId: "",
        pageNum: 1,
        pageSize: 10,
        status: "",
        createdAtStart: "",
        createdAtEnd: "",
      },
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
      verArry:[],
      verType:'',
      curItem:'', 
      userInfo: null,
      fd:''
    };
  },
  // 注册组件
  components: {
    Pagination,
    codeChoose
  },
  created() {
    this.getdata(this.formInline);
    this.getInfo();
  },
  methods: {
    getInfo() {
      service
        .get("/api/photon/getUserInfo", {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.userInfo = res.data;
            this.$store.commit("user", JSON.stringify(res.data));
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    }, 
    exportEx() {
      let url = getUrl(this.formInline);
      service
        .post("/api/admin/exportTransferRecordList" + url, {})
        .then((res) => {
          this.loading = false;
          console.log(res);
          if (res.code == 0) {
            window.open(
              baseURL + "/common/download?fileName=" + res.msg,
              "_blank"
            );
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    getdata(parameter) {
      let url = getUrl(parameter);
      service
        .get("/api/admin/getTransferRecordList" + url, {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.listData = res.rows;
            this.pageparm.currentPage = this.formInline.pageNum;
            this.pageparm.pageSize = this.formInline.pageSize;
            this.pageparm.total = res.total;
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    getOneUser(uid) {
      service
        .get("/api/admin/getUserInfo/" + uid, {})
        .then((res) => {
          if (res.code == 0) {
            this.editForm.toUserName = res.data.loginName;
            this.editFormVisible = true;
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageNum = parm.currentPage;
      this.formInline.pageSize = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    },
    handleEdit(index, row) {
      this.getOneUser(row.toUserId);
      this.editForm = row;
    },
    getParam(val,type){  
      this.headers = val ;
      this.editSaveAuth() 
    },  
    editSaveAuth(){ 
      let parm = {
          id: this.editForm.id,
          orderNo: this.editForm.orderNo,
          remark: this.editForm.auditResult,
          status: this.fd,
          userId: this.editForm.userId,
        },
       url = getUrl(parm); 
        reqJson('post',"/api/admin/verifyTransfer" + url, {},{
          headers:{
            ...this.headers
          }
        }) 
        .then((res) => {
          this.disabled = false;
          if (res.code == 0) {
            this.closeDialog();
            this.getdata(this.formInline);
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.disabled = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    
    // 编辑、增加页面保存方法
    submitForm(type) { 
        this.fd = type 
        this.disabled = true;  
        if(this.userInfo&&this.userInfo.verifyApi){ 
          this.verArry =  this.userInfo.verifyApi.split(',');
          if(this.verArry.includes('/api/admin/verifyTransfer')){
            this.$refs.codeRef.openDialog(); 
          }else{
            this.editSaveAuth();
          }
        }else{
           this.editSaveAuth();
        }

    
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
      this.editForm = "";
      this.$refs.editForm.resetFields();
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
</style>

 
 